#include "Speedhack2.h"

Speedhack2 g_pSpeedhack2;

void Speedhack2::Init()
{	
	Active = false;
	Multiplier = 5;
	RetAdd = FindPattern::Find((DWORD)GetModuleHandle(L"engine.dll"), 0x10652724-0x100, (BYTE*) SpeedhackFindPatternA, SpeedhackFindPatternB) + SpeedhackPatternOffset;
}

void Speedhack2::Enable()
{
	Active = true;
}

void Speedhack2::Disable()
{
	Active = false;
}

void Speedhack2::Set( bool Active )
{
	this->Active = Active;
}

void Speedhack2::SetMultiplier( int Multiplier )
{
	this->Multiplier = Multiplier;
}

void Speedhack2::Compute()
{
	DWORD* MyEsp;
	static int SpeedCnt;
	HasReturnAddressChanged=false;
	if (Active && (SpeedCnt % Multiplier))
	{
		__asm mov MyEsp, esp;

		for (int i = 0; i < 500; i++)
		{
			if (MyEsp[i] == RetAdd)
			{
				MyEsp[i] -= 5;
				HasReturnAddressChanged=true;
				break;
			}
		}
	}
	SpeedCnt++;
}
